import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:speed_random/app_styles.dart';
import 'package:speed_random/common/common_fuc.dart';
import 'package:speed_random/global_data.dart';
import 'package:speed_random/pages/home/rand_com/com_results/logic.dart';
import 'package:speed_random/pages/home/rand_com/com_results/state.dart';
import 'package:share_plus/share_plus.dart';

class ItemResultsColor extends StatelessWidget {
  final ComResultsLogic logic;
  final ComResultsState state;
  final Map<String, dynamic> numbers;
  final Color textColor;
  final Color bgColor;
  final Function({String newShareText,String newcopyText}) onShareTextChanged; // 添加回调函数

  const ItemResultsColor({
    Key? key,
    required this.logic,
    required this.state,
    required this.numbers,
    this.textColor = AppStyles.colorPageText,
    this.bgColor = AppStyles.colorPagebg,
    required this.onShareTextChanged, // 必须传入回调函数
  }) : super(key: key);




  @override
  Widget build(BuildContext context) {
    var zonx = "总项".tr+"：${numbers["list"].split(",").length}";
    var sumx = "总和".tr+"：${numbers["sum"]}";
    var newShareText = numbers["list"];
    onShareTextChanged(newShareText: newShareText,newcopyText: newShareText);

    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        // ... 已有代码 ...
        Wrap(
          spacing: 5.0,
          runSpacing: 5.0,
          children: numbers["list"].split(",").map<Widget>((number) { // 明确指定map返回Widget类型
            return Container(
              padding: EdgeInsets.all(5),
              decoration: BoxDecoration(
                color: commonFuc.hexToColor(number),
                borderRadius: BorderRadius.circular(8),
              ),
              child: Text(
                number.trim(),
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.white,
                ),
              ),
            );
          }).toList(),
        ),
        const SizedBox(height: 10),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                zonx,
                style:  TextStyle(
                  fontSize: 14,
                  color: textColor,
                ),
              ),

            ],
          )
      ],
    );
  }
}
